//
// Created by bolsen on 6/22/20.
//

#ifndef AEYECLIENTS_SOCKETDIAGNOSTICREADER_HPP
#define AEYECLIENTS_SOCKETDIAGNOSTICREADER_HPP

#include <atomic>
#include <cstddef>
#include <cstdint>
#include <string>

#include "DiagnosticAPI.hpp"
#include "QueueManager.hpp"
#include "SocketReaderDetail.hpp"

namespace aeye {

class SocketDiagnosticReader {
public:
  /*
   * pass the config in , also the port this particular reader should use
   * passing config is because it has list of all sensor ip addresses.
   * we use this later to filter invalid ip addr passd to process_packet.
   * probably will get rid of this later , it's a relic of there being only
   * one socketCloudReader.
   */
  SocketDiagnosticReader(const std::string& sensorAddr, uint16_t clientPort);
  ~SocketDiagnosticReader() noexcept;

  void run();
  void start();
  void stop() noexcept;
  DiagnosticData pop();
  void pushPcapPacket(std::vector<uint8_t>&& data);
  void setPcapMode(bool value) noexcept;
private:
  std::atomic<bool> isRunning{false};
  Reader reader_;
  bool pcapModeOn{false};
  QueueManager<std::vector<uint8_t>, QueueType::Waiting> pcap_queue_manager_;
  QueueManager<DiagnosticData, QueueType::Overwriting> frame_queue_manager_;


  static constexpr size_t  maxQueueSize = 3;
};

}



#endif //AEYECLIENTS_SOCKETDIAGNOSTICREADER_HPP
